package com.risk.web.controller.tk;

import com.risk.common.core.controller.BaseController;
import com.risk.common.core.domain.AjaxResult;
import com.risk.common.core.page.TableDataInfo;
import com.risk.common.utils.StringUtils;
import com.risk.kernel.domain.TkTask;
import com.risk.kernel.domain.TkTaskCase;
import com.risk.kernel.service.TkTaskServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Liwen
 * @createTime: 2025/1/2
 * @description:
 */
@RestController
@RequestMapping("/tk/task")
public class TkTaskController extends BaseController {

    @Autowired
    private TkTaskServiceI tkTaskService;

    /**
     * 查询分頁列表
     */
    @PreAuthorize("@ss.hasPermi('tk:task:list')")
    @GetMapping("/page/list")
    public TableDataInfo list(String keys) {
        startPage();
        List<TkTask> list = tkTaskService.selectTkTaskList(keys);
        return getDataTable(list);
    }


    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('tk:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tkTaskService.selectTkTaskById(id));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('tk:task:add')")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody TkTask tkTask) {
        String userName = StringUtils.isEmpty(getNickName()) ? getUsername() : getNickName();
        tkTask.setCreateBy(userName);
        return toAjax(tkTaskService.insertTkTask(tkTask));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('tk:task:edit')")
    @PutMapping(value = "/edit")
    public AjaxResult edit(@RequestBody TkTask tkTask) {
        return toAjax(tkTaskService.updateTkTask(tkTask));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('tk:task:remove')")
    @DeleteMapping("/bathRemove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tkTaskService.deleteTkTaskByIds(ids));
    }

    @GetMapping(value = "/getTaskNameList")
    @PreAuthorize("@ss.hasPermi('tk:case:taskName:list')")
    public TableDataInfo getTaskNameList() {
        List<TkTaskCase> list = tkTaskService.getTaskNameList();
        return getDataTable(list);

    }
}
